package com.yy.controller;

import com.yy.mapper.DptMapper;
import com.yy.pojo.Dpt;
import com.yy.pojo.Meet;
import com.yy.pojo.User;
//import com.yy.service.DptRepository;
import com.yy.service.DptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: yy
 * @Date
 */
@RestController
@Controller
@RequestMapping("/dpt")
public class DptController {
    @Autowired
    DptService dptService;

//    @Autowired
//    DptRepository dptRepository;

//    @PostMapping("/save")
//    public String save(@RequestBody Dpt dpt){
//        Dpt result = dptService.addDpt(dpt);
//        if (result != null){
//            return "success";
//        }else {
//            return "error";
//        }
//    }


    /**
     * 添加一个部门
     */
//    @GetMapping ("/addDpt")
//    public String addDpt(){
//        Dpt dpt = new Dpt("044","d","fhuhud","78","fse");
//        dptService.addDpt(dpt);
//        return "ok";
//    }

    @PostMapping("/addDpt")
    public int addDpt(@RequestBody Dpt dpt){
        return dptService.addDpt(dpt);
    }




    /**
     * 查看部门
     */
    @GetMapping("/getDptList")
    public List<Dpt> getDptList(){
        List<Dpt> dptList = dptService.getDptList();
        for (Dpt dpt : dptList){
            System.out.println(dpt);
        }
//        Pageable pageable = PageRequest.of(0,6)
        return dptList;
    }



//    @RequestMapping ("/deleteDpt/{dptId}")
//    public String deleteDpt(@PathVariable String dptId){
//        return  dptService.deleteDpt(dptId).toString();
//
//    }

//    @GetMapping("/deleteDpt")
//    public String deleteDpt(){
//        dptService.deleteDpt("001");
//        return "ok";
//    }
    /**
     * 删除部门
     */
    @DeleteMapping("/deleteDpt/{dptId}")
    public int deleteDpt(@PathVariable("dptId") String dptId){
        return dptService.deleteDpt(dptId);
    }


    //    @DeleteMapping("/deleteById/{dptId}")
//    public void deleteById(@PathVariable("dptId") String dptId){
//        dptRepository.deleteById(dptId);
//    }


    @GetMapping("/findBydptId/{dptId}")
    public Dpt findBydptId(@PathVariable ("dptId") String dptId){
        return dptService.findBydptId(dptId);

    }
    @PutMapping("/update")
    public String update(@RequestBody Dpt dpt){
            int result=dptService.addDpt(dpt);
            if (result!=0){
                return "success";
            }else {
                return "error";
            }

    }
}
